package com.hua.zhifubao;

import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.TextView;

import androidx.recyclerview.widget.RecyclerView;

import java.util.ArrayList;
import java.util.List;

public class RcAdapter extends RecyclerView.Adapter<RcAdapter.RcViewHolder> {

    private List<RcBean> list = new ArrayList<>();

    public SetItemOnClickListener listener;

    public RcAdapter( List<RcBean> list) {
        this.list = list;
    }

    @Override
    public RcViewHolder onCreateViewHolder(ViewGroup parent, int viewType) {
        return new RcViewHolder(LayoutInflater.from(parent.getContext()).inflate(R.layout.item_rc, parent, false));
    }

    @Override
    public void onBindViewHolder(RcViewHolder holder, int position) {
        holder.tv_name.setText(list.get(position).getName());
        holder.tv_money.setText(String.valueOf(list.get(position).getMoney()));
        holder.itemView.setOnClickListener(v -> {
            listener.setItemOnClickListener(position);
        });
    }

    @Override
    public int getItemCount() {
        return list.size();
    }

    class RcViewHolder extends RecyclerView.ViewHolder {

        TextView tv_name, tv_money;

        public RcViewHolder(View v) {
            super(v);
            tv_name = v.findViewById(R.id.tv_name);
            tv_money = v.findViewById(R.id.tv_money);
        }
    }

    public void setOnClickListener(SetItemOnClickListener listener) {
        this.listener = listener;
    }

    public interface SetItemOnClickListener {
        void setItemOnClickListener(int position);

    }

}
